<?php

class publicRequesrt
{
    public $bizContent;
    public $charset;
    public $companyId;
    public $signType;
    public $timestamp;
    public $sign;
}

function RsaSign($data)
{
    // 设置私钥
    $privateKey = "-----BEGIN RSA PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCTmS3yV/WRbLlXO7bPjC/mDkhH33URyTG7fwLeGvVbyZ6EQsbX09cazKbjI/K+m9dRSHXJBZbW/vflhPbJglZi7vNcEn+0vD7tvywgmbUF0bIktB0v2yoxC7y8/o+hp86ZvvXXBQShBLMaPxfpq6OppxW3Bwun/JmJiho1Dk54zaDdSVsM2yYAPCHSxE9X+5tC87s2c+YWGXTmscg7bBpvxDKz1TYKsUzvgv8RidAuZWluVIsyCeVDP/driZHh7sKwyNBOcnXlH++Dkha3yQ1gpmMZMwo+uMNKD6gqueyAdkwTky4vliVr7ssDHgwCucitj5SW+h6k2c2yYHOFcaYPAgMBAAECggEAdNM8w+INNCMLfFl+dD6wtvY9De53+jD2lUKN4YETDajDOEqmmrRJQSQVQBn3DBnLzsF8wTUUVG4RhvC8aXkpqTsbEphtzn9li8bSRaeD2exFhbmulG9zsMhqhmkzBLAO3jCA48VMCarvnGmuIr1BWIowrOL9veQ5Ht1Zqv78664R4KvxVgqKShzVdT+uMDRAT0vJMA+ffYIdsDAqgCeUgacCghLVWsk/KV0HDEEHC/Ns+d+NZ3blFUxE0s9hnHKFBBAjxwvJLiK+Zou9cEGOeUvDzSdB0sTczTbLEfrrVmk+sHBYq0wnmf7aJ+mKopASkwIuEMU2SeHcS0mYEObeMQKBgQD3WjoNhRUxCjn0RhEwOi0g+wnaCgERqqUg0zpAYrtk+fx/onuW3GutEPkHYtwPFPgt/4teLFCWw3b/nmx5B33ng3RT518mbh/Yp8v1t6B1xE0KI4PMpry7LumCUPpfqqFcdjQ/vJAOhtSqakrt355rrl7XSli0CVhvbdiwTh8BSQKBgQCYwiqKMCkXlmoYGeNdfz5cBVujCoU9cY+ktapmCMccbi/yyOpd9wKmbNFbaPl+BCYlm67cQkWASKcoI/OBtLYMoQ7cpszL0NHxdCZ7gsvh2H9Iinp5bBF94e7gwABwytBObNGfkqipuWOuBOuaZzfS0BNvLS112CH3Y6WZPszElwKBgQCo9Sq+XW9yRgf8QXgwNyzoYFIEa9z7ElMlLuOVY1uZx+Cf1n8RN5MdboCMeQzUCIDV+r5aH28U7IN2a+KwcVuhLnvhbCPkfkiml0eMmley2dm92TCINESqn4rFh0be3hDGtb9O4iCMq7DMjzqLbboq17rU2GXq5I9R3firxVEMcQKBgFElo+9wkgOjtYxEBFHgjEHZ3soHhqwTLVkz3+b/9rWVmwb/z/BGjTPXToeehhp5HcKQpxz+X2k8Lv/VyT83vhWLYRe5y8ThkwUOzHqECsZYeZURauohjFEwufLOS+2e73UZvWllQQ+YGemRV47YEgF84zYF68ZUIAcI+ikkASbVAoGAd0R1V+Jw9GBPgB3ufWNZiDxm5pQekmAwEXNmz0wkNR4IVencNgltjvHXEUsiHvv9tIxAEpYQXvd8qhhcsxFly4v9d7gaDydBd5bQNetrr8gEtjV9ymXqm0aM9J4r7EjEdioSFjGqt7r5CkvYltFcwYL+ODeZMYCoUTqQ2XbFLZg=
-----END RSA PRIVATE KEY-----";

    $res = openssl_pkey_get_private($privateKey);
    // 使用私钥计算签名
    openssl_sign($data, $signature, $res, "SHA256");
    $signature = base64_encode($signature);
    echo "签名: $signature \r\n";

    return $signature;
}

function http_post($url, $data)
{
    // 设置请求选项
    $options = [
        'http' => [
            'method' => 'POST',
            'header' => "Content-type: application/json\r\n",
            'content' => $data
        ]
    ];

    // 创建流上下文
    $context = stream_context_create($options);

    // 发起请求
    $response = file_get_contents($url, false, $context);

    // 处理响应
    if ($response !== false) {
        echo "Response: $response \r\n";
    } else {
        echo "Failed to get response";
    }
}



